package com.seven.log.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class LogWriter {
    /*@Value("${auction.exchange-name}")
    private String exchangeName;
    *//*@Value("${auction.queue-name}")
    private String queueName;*//*
    @Value("${auction.log-path}")
    private String logPath;*/

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "log_queue", declare = "true"),
            exchange = @Exchange(name = "log_exchange", declare = "true", type = "topic"),
            key = "log."
    ))
    @RabbitHandler
    public void handleLog(@Payload Map msg, Channel channel, @Headers Map headers){
        System.out.println("接受到了");
        System.out.println("msg"+msg);
        //签收确认
        long tag = (long) headers.get(AmqpHeaders.DELIVERY_TAG);
        try {
            channel.basicAck(tag,false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
